﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Micrhard.FMCG.Server.Interface;
using Microsoft.Practices.Unity;
using Micrhard.FMCG.Server.Models;
using Microhard.Permission.Interface;
using Microhard.Permission.MVCFilter;
using Microhard.WebUI.Models;
using Microhard.Permission_MembershipImpl;
using Microhard.Core;
using Micrhard.FMCG.Server.Impl;
using FluentValidation.Mvc;

namespace Microhard.FMCG.WebUI.Areas.BaseData.Controllers
{
    public class CMPProductController : MicroHardBaseController<ProductModel>
    {
        private ICmpProduct _resp = null;
        [Dependency]
        public ICmpProduct Category
        {
            set
            {
                base._repository = value;
                _resp = value;
            }
            get
            {
                return _resp;
            }
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult GetList(AttriubteOfSelectList ctrAttr)
        {
            var userName = this.GetCurrentUserName();
            IEmployee emp = IoC.Resolve<IEmployee>();
            var cmp = emp.GetUserCompanyByUserName(userName);
            if (cmp != null)
            {
                var prds = _resp.GetPrdsByCompanyID(cmp.CompanyID);
                ctrAttr.Data = prds.Select(r => new SelectData
                {
                    ID = r.ProductID.ToString(),
                    Name = r.Mark
                }).ToList();
            }
            return View("SelectList", ctrAttr);
        }
    }
}
